# --*-- coding: utf-8 --*--

import configparser
from configparser import NoOptionError, NoSectionError
import os
import codecs
import traceback
from typing import NoReturn, Dict

from src.public.public import Public
# from src.log.log import Log
from src import logger

PROJECT_DIR = os.path.dirname(
	os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
)

CONFIG_PATH = os.path.join(PROJECT_DIR, "Config", "config.ini")


# logger = Log()


class GetConfig(object):
	@staticmethod
	def get_config() -> configparser.ConfigParser:
		config = configparser.ConfigParser()
		with open(
				file=CONFIG_PATH, mode="rb"
		) as f:  # 2018-6-10 BEGIN 判断文件的编码类型 如果是UTF-8 BOM格式，则将其转化为无BOM格式
			s = f.read()
		if s.startswith(codecs.BOM_UTF8):  # 带BOM的文件是以 b'\xef\xbb\xbf' 开头
			s = s[len(codecs.BOM_UTF8):]  # 截取 b'\xef\xbb\xbf' 到文件结尾
			with open(file=CONFIG_PATH, mode="wb") as f:  # 保存为无BOM格式
				f.write(s)
		coding = Public.get_file_coding(filepath=CONFIG_PATH).get("encoding")
		config.read(
			filenames=CONFIG_PATH, encoding=coding
		)
		# print(config)# 2018-6-10 END 判断文件的编码类型 如果是UTF-8 BOM格式，则将其转化为无BOM格式
		return config

	def _write_config(self, config):
		coding = Public.get_file_coding(filepath=CONFIG_PATH).get("encoding")
		with open(CONFIG_PATH, mode='w', encoding=coding) as f:
			config.write(f)

	def _prop_setter(self, section, option, value):
		try:
			config = self.get_config()
			config.set(section=section, option=option, value=value)
			self._write_config(config)
		except Exception as e:
			err_msg = f'.../项目目录/Config/config.ini更新配置 {section}.{option} 选项 值 "{value}" 出错。\n错误详情：\n {traceback.format_exc()}'
			logger.warning(err_msg)
			raise RuntimeError(err_msg) from e  # 供web捕获异常，前台提示

	@property
	def project_dir(self) -> str:
		# return self.get_config().get(section="PROJECT", option="project_dir")
		# 不在需要配置项目路径，项目迁移更加灵活。
		return PROJECT_DIR

	@property
	def login_url(self) -> str:
		section = "URL"
		option = "login_url"
		default = "/sys/auth/login"
		try:
			value = self.get_config().get(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@property
	def test_password(self) -> str:
		section = "PASSWORD"
		option = "test_password"
		default = "zfs123456"
		try:
			value = self.get_config().get(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@property
	def project_version(self) -> str:
		section = "PROJECT"
		option = "project_version"
		default = "3.0.0"
		try:
			value = self.get_config().get(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@property
	def manage_case_type(self) -> str:
		section = "PROJECT"
		option = "manage_case_type"
		default = 'excel'
		try:
			value = self.get_config().get(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@property
	def browser_type(self) -> str:
		section = "PROJECT"
		option = "browser_type"
		default = "Chrome"
		try:
			value = self.get_config().get(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@browser_type.setter
	def browser_type(self, value) -> NoReturn:
		section = "PROJECT"
		option = "browser_type"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def browser_path(self) -> str:
		section = "PROJECT"
		option = "browser_path"
		default = None
		try:
			value = self.get_config().get(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@browser_path.setter
	def browser_path(self, value) -> NoReturn:
		section = "PROJECT"
		option = "browser_path"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def timeout(self) -> int:
		section = "TEST"
		option = "timeout"
		default = 10
		try:
			value = self.get_config().getint(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@timeout.setter
	def timeout(self, value) -> NoReturn:
		section = "TEST"
		option = "timeout"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def headless(self) -> bool:
		section = "TEST"
		option = "headless"
		default = False
		try:
			value = self.get_config().getboolean(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@headless.setter
	def headless(self, value) -> NoReturn:
		section = "TEST"
		option = "headless"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def DEBUG(self):
		section = "CONSOLE_LOG_COLOR"
		option = "DEBUG"
		default = "white"
		try:
			value = self.get_config().get(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@property
	def INFO(self):
		section = "CONSOLE_LOG_COLOR"
		option = "INFO"
		default = "green"
		try:
			value = self.get_config().get(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@property
	def WARNING(self):
		section = "CONSOLE_LOG_COLOR"
		option = "WARNING"
		default = "yellow"
		try:
			value = self.get_config().get(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@property
	def ERROR(self):
		section = "CONSOLE_LOG_COLOR"
		option = "ERROR"
		default = "red"
		try:
			value = self.get_config().get(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@property
	def CRITICAL(self):
		section = "CONSOLE_LOG_COLOR"
		option = "ERROR"
		default = "bold_red"
		try:
			value = self.get_config().get(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@property
	def send_email(self) -> bool:
		section = "EMAIL"
		option = "send_email"
		default = False
		try:
			value = self.get_config().getboolean(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@send_email.setter
	def send_email(self, value) -> NoReturn:
		section = "EMAIL"
		option = "send_email"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def gen_report(self) -> bool:
		section = "EMAIL"
		option = "gen_report"
		default = True
		try:
			value = self.get_config().getboolean(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@gen_report.setter
	def gen_report(self, value) -> NoReturn:
		section = "EMAIL"
		option = "gen_report"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def smtp_login_name(self) -> str:
		section = "EMAIL"
		option = "smtp_login_name"
		default = None
		try:
			value = self.get_config().get(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@smtp_login_name.setter
	def smtp_login_name(self, value) -> NoReturn:
		section = "EMAIL"
		option = "smtp_login_name"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def smtp_login_passwd(self) -> str:
		section = "EMAIL"
		option = "smtp_login_passwd"
		default = None
		try:
			value = self.get_config().get(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@smtp_login_passwd.setter
	def smtp_login_passwd(self, value) -> NoReturn:
		section = "EMAIL"
		option = "smtp_login_passwd"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def sender_address(self) -> str:
		section = "EMAIL"
		option = "sender_address"
		default = "********@outlook.com"
		try:
			value = self.get_config().get(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@sender_address.setter
	def sender_address(self, value) -> NoReturn:
		section = "EMAIL"
		option = "sender_address"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def receiver_address(self) -> list:
		section = "EMAIL"
		option = "receiver_address"
		default = []
		try:
			address = self.get_config().get(section=section, option=option)
			value = []
			for _address_splited in address.split(","):
				if _address_splited:
					value.append(_address_splited.strip())
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@receiver_address.setter
	def receiver_address(self, value) -> NoReturn:
		section = "EMAIL"
		option = "receiver_address"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def smtp_server_address(self) -> str:
		section = "EMAIL"
		option = "smtp_server_address"
		default = "smtp.exmail.qq.com"
		try:
			value = self.get_config().get(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@smtp_server_address.setter
	def smtp_server_address(self, value) -> NoReturn:
		section = "EMAIL"
		option = "smtp_server_address"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def smtp_port(self) -> int:
		section = "EMAIL"
		option = "smtp_port"
		default = 465
		try:
			value = self.get_config().getint(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@smtp_port.setter
	def smtp_port(self, value) -> NoReturn:
		section = "EMAIL"
		option = "smtp_port"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def smtp_tls(self) -> bool:
		section = "EMAIL"
		option = "smtp_tls"
		default = True
		try:
			value = self.get_config().getboolean(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@smtp_tls.setter
	def smtp_tls(self, value) -> NoReturn:
		section = "EMAIL"
		option = "smtp_tls"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def smtp_ssl(self) -> bool:
		section = "EMAIL"
		option = "smtp_ssl"
		default = True
		try:
			value = self.get_config().getboolean(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@smtp_ssl.setter
	def smtp_ssl(self, value) -> NoReturn:
		section = "EMAIL"
		option = "smtp_ssl"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def email_title(self) -> str:
		section = "EMAIL"
		option = "email_title"
		default = "接口自动化测试报告邮件..."
		try:
			value = self.get_config().get(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@email_title.setter
	def email_title(self, value) -> NoReturn:
		section = "EMAIL"
		option = "email_title"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def email_text(self) -> str:
		section = "EMAIL"
		option = "email_text"
		default = "详细测试报告请查看附件..."
		try:
			value = self.get_config().get(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@email_text.setter
	def email_text(self, value) -> NoReturn:
		section = "EMAIL"
		option = "email_text"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def title(self) -> str:
		section = "REPORT"
		option = "title"
		default = "Web自动化测试报告"
		try:
			value = self.get_config().get(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@title.setter
	def title(self, value) -> NoReturn:
		section = "REPORT"
		option = "title"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def description(self) -> str:
		section = "REPORT"
		option = "description"
		default = "报告描述"
		try:
			value = self.get_config().get(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@description.setter
	def description(self, value) -> NoReturn:
		section = "REPORT"
		option = "description"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def backups(self) -> bool:
		section = "REPORT"
		option = "backups"
		default = False
		try:
			value = self.get_config().getboolean(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@property
	def dbtype(self) -> str:
		section = "DATABASE"
		option = "dbtype"
		default = "MySQL"
		try:
			value = self.get_config().get(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@dbtype.setter
	def dbtype(self, value) -> NoReturn:
		section = "DATABASE"
		option = "dbtype"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def query_result_type(self) -> str:
		section = "DATABASE"
		option = "query_result_type"
		default = "dict"
		try:
			value = self.get_config().get(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@query_result_type.setter
	def query_result_type(self, value):
		section = "DATABASE"
		option = "query_result_type"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def dsn(self) -> str:
		section = "ORACLE"
		option = "dsn"
		default = "DSN_Oracle"
		try:
			value = self.get_config().get(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@dsn.setter
	def dsn(self, value) -> NoReturn:
		section = "ORACLE"
		option = "dsn"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def user_oracle(self) -> str:
		section = "ORACLE"
		option = "user"
		default = "sys"
		try:
			value = self.get_config().get(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@user_oracle.setter
	def user_oracle(self, value) -> NoReturn:
		section = "ORACLE"
		option = "user"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def passwd_oracle(self) -> str:
		section = "ORACLE"
		option = "passwd"
		default = None
		try:
			value = self.get_config().get(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@passwd_oracle.setter
	def passwd_oracle(self, value) -> NoReturn:
		section = "ORACLE"
		option = "passwd"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def host(self) -> str:
		section = "MYSQL"
		option = "host"
		default = "localhost"
		try:
			value = self.get_config().get(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@host.setter
	def host(self, value) -> NoReturn:
		section = "MYSQL"
		option = "host"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def user_mysql(self) -> str:
		section = "MYSQL"
		option = "user"
		default = "root"
		try:
			value = self.get_config().get(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@user_mysql.setter
	def user_mysql(self, value) -> NoReturn:
		section = "MYSQL"
		option = "user"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def passwd_mysql(self) -> str:
		section = "MYSQL"
		option = "passwd"
		default = "root"
		try:
			value = self.get_config().get(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@passwd_mysql.setter
	def passwd_mysql(self, value) -> NoReturn:
		section = "MYSQL"
		option = "passwd"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def port(self) -> int:
		section = "MYSQL"
		option = "port"
		default = 3306
		try:
			value = self.get_config().getint(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@port.setter
	def port(self, value) -> NoReturn:
		section = "MYSQL"
		option = "port"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def charset(self) -> str:
		section = "MYSQL"
		option = "charset"
		default = 'utf8'
		try:
			value = self.get_config().get(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@charset.setter
	def charset(self, value) -> NoReturn:
		section = "MYSQL"
		option = "charset"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def notifier_enable(self) -> bool:
		section = "NOTIFIER"
		option = "enable"
		default = False
		try:
			value = self.get_config().getboolean(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@notifier_enable.setter
	def notifier_enable(self, value) -> NoReturn:
		section = "NOTIFIER"
		option = "enable"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def access_token(self) -> str:
		section = "NOTIFIER"
		option = "access_token"
		default = "xxxxxxxxxxx"
		try:
			value = self.get_config().get(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@access_token.setter
	def access_token(self, value) -> NoReturn:
		section = "NOTIFIER"
		option = "access_token"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def is_at_all(self) -> bool:
		section = "NOTIFIER"
		option = "is_at_all"
		default = True
		try:
			value = self.get_config().getboolean(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@is_at_all.setter
	def is_at_all(self, value) -> NoReturn:
		section = "NOTIFIER"
		option = "is_at_all"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def at_mobiles(self) -> list:
		section = "NOTIFIER"
		option = "at_mobiles"
		default = []
		try:
			value = self.get_config().get(section=section, option=option)
			value = [no.strip() for no in value.split(",")]
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@at_mobiles.setter
	def at_mobiles(self, value) -> NoReturn:
		section = "NOTIFIER"
		option = "at_mobiles"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def responsible_person_email(self) -> Dict:
		section = "ResponsiblePersonEmail"
		default = {}
		try:
			items = self.get_config().items(section=section)
			value = dict(items)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(
				'.../项目目录/Config/config.ini文件未配置 %s 选项，将采用默认值"%s"' %
				(section, value)
			)
		return value

	@property
	def ResponsiblePersonEmail(self) -> str:
		section = "ResponsiblePersonEmail"
		option = 'weixinxiu'
		default = "smtp-mail.outlook.com"
		try:
			value = self.get_config().get(section=section, option=option)
		except (NoOptionError, NoSectionError):
			value = default
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{option} 选项，将采用默认值"{value}"')
		return value

	@responsible_person_email.setter
	def responsible_person_email(self, value) -> NoReturn:
		section = "EMAIL"
		option = "receiver_address"
		self._prop_setter(section=section, option=option, value=value)

	@property
	def base_url(self) -> NoReturn:
		section = "URL"
		protocol_option = 'protocol'
		protocol_default = "https"
		ip_option = 'ip'
		ip_default = "fol.ztccloud.com.cn"
		port_option = 'port'
		port_default = ""
		try:
			protocol = self.get_config().get(section=section, option=protocol_option)
			ip = self.get_config().get(section=section, option=ip_option)
			port = self.get_config().get(section=section, option=port_option)
			base_url = protocol + "://" + ip
			if port:
				base_url += ":" + port
			return base_url
		except (NoOptionError, NoSectionError):
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{protocol_option} 选项，将采用默认值"{protocol_default}"')
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{ip_option} 选项，将采用默认值"{ip_default}"')
			logger.warning(f'.../项目目录/Config/config.ini文件未配置 {section}.{port_option} 选项，将采用默认值"{port_default}"')


Config = GetConfig()

if __name__ == "__main__":
	print(Config.base_url)
